The need to process bits in a fewer number than they are fetched from computer memory may arise in many applications. With many microprocessors such as the Intel 80386 or 80486, for instance, bits may be fetched from memory or otherwise manipulated in groups of eight bits, 16 bits or 32 bits. But often it is preferable or necessary to further process the bits singly, in pairs or in other portions of the fetched group.
A good example of this need is in the process for converting a one bit per pixel image to a different format, such as converting a monochrome image into a color image. Such conversion occurs in the process of colorizing fonts, icons or cursors that are initially constructed as one-bit per pixel images. A prior technique for converting a monochrome image to a multibit image is shown in the assembly language code in Table 1 below:
TABLE 1 ______________________________________ ; ds:esi .fwdarw. points to the source bytes to convert ; es:edi .fwdarw. points to the destination surface ; edx .fwdarw. number of bytes to convert. ; fs:Color Expand Table .fwdarw. prebuilt color convert table to convert any possible sequence of 2 bits to 2 WORDS {DWORD} OuterLoop: mov bl,[esi] ;get one source byte [= 8 pixels of 1 bit each] inc esi ;point to next source byte ror ebx,8 ;get the byte into the high byte of EBX. mov ch,4 ;4 sets of two bits each of source data InnerLoop: xor bl,bl ;initialize (clear out any existing bits) rol ebx,2 ;get the next two bits into bl. shl bx,2 ;multiply by 4 to access a DWORD table mov eax, fs:ColorExpandTable[bx] ;expand the two bits to a DWORD stosd ;store the 2 color converted pels dec ch ;one more set of two bits done. jnz InnerLoop ;continue if there are more pairs of bits to do. dec edx ;one more byte of the source done. jnz OuterLoop ;do all the bytes in the source. ______________________________________
With this technique, eight-bit bytes (source bytes) of the one-bit per pixel images are divided into two-bit portions. These two-bit portions form an index to a 4 entry color expand table which expands each bit to 16 bits. Each entry in the color expand table is thus 32 bits. The CH portion of the ECX register is set to four and decremented after each two-bit portion is expanded. A new source byte is fetched after the prior source byte is completely expanded.
The drawbacks of this and similar prior techniques are twofold. First, they require a register or memory location for keeping count of the number of two-bit portions processed. Using a register consumes a limited resource. On the other hand, a memory location is much slower to access and its use adds considerable delay. Second, these techniques require the register or memory location to be initialized each time a new source byte is processed. This initialization requires a step that must be executed thousands of times in the process of converting a one-bit image to a multibit image, adding unwanted delay.
An object of this invention, therefore, is to provide an improved method for fetching a group of bits from computer memory and providing portions of the group to a computer process. Another object is to provide such a method that requires fewer instructions and fewer registers or memory locations than prior methods. More particularly, an object of this invention is to provide such a method for expanding a fewer-bit per pixel image to a greater-bit per pixel image.